<template>
	<view class="tui-safe-area">
		<view class="tui-address" v-if="addressList.length!=0">
			<block v-for="(item,index) in addressList" :key="index" >
				<tui-list-cell padding="0">
					<view class="tui-address-flex">
						<view class="tui-address-left">
							<view class="tui-address-main">
								<view class="tui-address-name tui-ellipsis">{{item.name}}</view>
								<view class="tui-address-tel">{{item.phoneNumber}}</view>
							</view>
							<view class="tui-address-detail">
								<view class="tui-address-label" v-if="item.defaultStatus==1">默认</view>
								<text>{{item.province}}{{item.city}}{{item.region}}{{item.detailAddress}}</text>
							</view>
						</view>
						<view class="tui-address-imgbox" @click="editAddr(item.id)">
							<image class="tui-address-img" src="/static/img/my/icon_addr_edit.png" />
						</view>
					</view>
				</tui-list-cell>
			</block>
		</view>
		<view class="empty_address" v-else >
			<u-empty  text="没有收货地址" mode="address"></u-empty>
		</view>
		<!-- 新增地址 -->
		<view class="tui-address-new">
			<tui-button shadow shape="circle" type="danger" height="88rpx" @click="addAddr">+ 新增收货地址</tui-button>
		</view>
		<u-no-network tips="哎呀，网络信号丢失"></u-no-network>
		<failTimeout v-show="failTimeout"></failTimeout>
	</view>
</template>

<script>
	import UmsMemberReceiveAddressController from '../../api/UmsMemberReceiveAddressController.js'
	export default {
		data() {
			return {
				failTimeout:false,
				addressList: []
			}
		},
		onLoad: function(options) {

		},
		onShow: function() {
			UmsMemberReceiveAddressController.list().then(res=>{
				if(res.data.code==200){
					this.addressList=res.data.data
				}
			}).catch(err=>{
				if(err.errMsg=='request:fail timeout'){
					this.failTimeout=true
				}
			})
			
		},
		methods: {
			editAddr(id) {
				uni.navigateTo({
					url: "/pages/address/editAddress?addressId="+id
				})
			},
			addAddr(){
				uni.navigateTo({
					url: "/pages/address/addAddress"
				})
			}
		}
	}
</script>

<style scoped>
	.tui-address {
		width: 100%;
		padding-top: 20rpx;
		padding-bottom: 160rpx;
	}
	.tui-address-flex {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.tui-address-main {
		width: 600rpx;
		height: 70rpx;
		display: flex;
		font-size: 30rpx;
		line-height: 86rpx;
		padding-left: 30rpx;
	}

	.tui-address-name {
		min-width: 120rpx;
		max-width: 400rpx;
		height: 60rpx;
		overflow: hidden;
        word-break: break-all;  /* break-all(允许在单词内换行。) */
        text-overflow: ellipsis;  /* 超出部分省略号 */
        display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
        -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
        -webkit-line-clamp: 1; /** 显示的行数 **/
	}

	.tui-address-tel {
		margin-left: 20rpx;
	}

	.tui-address-detail {
		font-size: 24rpx;
		word-break: break-all;
		padding-bottom: 25rpx;
		padding-left: 25rpx;
		padding-right: 120rpx;
	}

	.tui-address-label {
		padding: 5rpx 8rpx;
		flex-shrink: 0;
		background: #e41f19;
		border-radius: 6rpx;
		color: #fff;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		font-size: 25rpx;
		line-height: 25rpx;
		transform: scale(0.8);
		transform-origin: center center;
		margin-right: 6rpx;
	}

	.tui-address-imgbox {
		width: 80rpx;
		height: 100rpx;
		position: absolute;
		display: flex;
		justify-content: center;
		align-items: center;
		right: 10rpx;
	}

	.tui-address-img {
		width: 36rpx;
		height: 36rpx;
	}

	.tui-address-new {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 999;
		padding: 20rpx 25rpx 30rpx;
		box-sizing: border-box;
		background: #fafafa;
	}

	.tui-safe-area {
		padding-bottom: env(safe-area-inset-bottom);
	}
	.empty_address{
		margin-top: 150rpx;
	}
</style>
